package mb.admin.webbean;

import java.util.ArrayList;

import javax.faces.model.SelectItem;

import mb.admin.dao.NewsDAO;
import mb.admin.data.NewsData;
import mb.commons.CalendarManager;

/**
 * Manager widoku 'news.jsp'
 * 
 * @author Michał Budziło
 * 
 */
public class NewsManager {

	private NewsDAO dao;
	private ArrayList<NewsData> dataList;
	private NewsData editedData;
	private NewsData newData;
	private CalendarManager calendar;
	private ArrayList<SelectItem> jezykList;

	/**
	 * Konstruktor
	 */
	public NewsManager() {
		dao = new NewsDAO();
		calendar = new CalendarManager();
		jezykList = new ArrayList<SelectItem>();
		dataList = dao.getNewsList();

	}

	/**
	 * Metoda przygotowuje dane przez dodaniem newsa
	 */
	public void prepareAddData() {
		newData = new NewsData();

	}

	/**
	 * Metoda dodane do bazy danych nowego news'a
	 */
	public void addData() {
		dao.insertData(newData);
		refreshData();
	}

	/**
	 * Metoda przygotowuje dane przed edycją news'a
	 */
	public void prepareEditData() {

	}

	/**
	 * Metoda edytuje w bazie danych news'a
	 */
	public void editData() {
		dao.updateData(editedData);
	}

	/**
	 * Metoda usuwa z bazy danych news'a
	 */
	public void deleteData() {
		dao.deleteData(editedData);
		refreshData();
	}

	/**
	 * Metoda pobiera z bazy danych listę news'ów
	 */
	public void refreshData() {
		dataList = dao.getNewsList();
	}

	/**
	 * @return the dataList
	 */
	public ArrayList<NewsData> getDataList() {
		return dataList;
	}

	/**
	 * @param dataList
	 *            the dataList to set
	 */
	public void setDataList(ArrayList<NewsData> dataList) {
		this.dataList = dataList;
	}

	/**
	 * @return the editedData
	 */
	public NewsData getEditedData() {
		return editedData;
	}

	/**
	 * @param editedData
	 *            the editedData to set
	 */
	public void setEditedData(NewsData editedData) {
		this.editedData = editedData;
	}

	/**
	 * @return the newData
	 */
	public NewsData getNewData() {
		return newData;
	}

	/**
	 * @param newData
	 *            the newData to set
	 */
	public void setNewData(NewsData newData) {
		this.newData = newData;
	}

	/**
	 * @return the calendar
	 */
	public CalendarManager getCalendar() {
		return calendar;
	}

	/**
	 * @param calendar
	 *            the calendar to set
	 */
	public void setCalendar(CalendarManager calendar) {
		this.calendar = calendar;
	}

	/**
	 * @return the jezykList
	 */
	public ArrayList<SelectItem> getJezykList() {
		return jezykList;
	}

	/**
	 * @param jezykList
	 *            the jezykList to set
	 */
	public void setJezykList(ArrayList<SelectItem> jezykList) {
		this.jezykList = jezykList;
	}

}
